<?
  if ($val) 
  {
    $rec = db_read_rec( sprintf("SELECT image FROM images WHERE id=%d", $val) );

    if ($rec)
    {
      header("Content-type: image/jpeg");
      echo $rec["image"];
    }
  }
?>
